package com.xia.qianke.serivce;

import com.xia.qianke.dao.ClientDAO;
import com.xia.qianke.dao.CountDAO;
import com.xia.qianke.entity.QkPostData;
import com.xia.qianke.entity.client.Client;
import com.xia.qianke.utils.HttpUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;


/**
 * @ClassName Qk
 * @Description TODO
 * @Author XJY
 * @Date 2022/7/6 16:28
 * @Version 1.0
 **/
@Service
public class Qk {
    @Autowired
    JdbcTemplate jdbcTemplate;
    //进件入库
    @Autowired
    ClientDAO clientDAO;
    @Autowired
    HttpUtils httpUtils;
    @Autowired
    CountDAO countDAO;
    public void addMd5(Client client){
        String phoneMd5 = DigestUtils.md5DigestAsHex (client.getPhone ().getBytes (StandardCharsets.UTF_8));
        clientDAO.addMd5 (phoneMd5);
    }

    //进件前置检查，true表示不存在可以接收，false表示存在撞库不予接收
    public Boolean checkUser(String phoneMd5){
        Integer count = clientDAO.checkUser (phoneMd5);
        if (count == 0){
            return true;
        }
        return false;
    }
    //向仟客后台发送客户数据
    public QkPostData postData(Client client){
        countDAO.saveTimes ();
        return httpUtils.postData (client);
    }
    //向运营发送进件消息
    public void sendVxMsg(){
        httpUtils.PostVxMsg ();
    }
}
